#include "apm32f10x.h"
#include "apm32f10x_gpio.h"
#include "apm32f10x_rcm.h"
// #include "apm32f10x_eint.h"
// #include "apm32f10x_usart.h"
#include "apm32f10x_misc.h"

#include "SEGGER_RTT.h"

void Delay(void)
{
    volatile uint32_t delay = 0x4fffff;

    while(delay--);
}

void gpio_init()
{
    GPIO_Config_T  configStruct;

    /* Enable the GPIO_LED Clock */
    RCM_EnableAPB2PeriphClock(RCM_APB2_PERIPH_GPIOB);

    /* Configure the GPIO_LED pin */
    configStruct.pin = GPIO_PIN_2;
    configStruct.mode = GPIO_MODE_OUT_PP;
    configStruct.speed = GPIO_SPEED_50MHz;

    GPIO_Config(GPIOB, &configStruct);
    GPIO_ResetBit(GPIOB,GPIO_PIN_2);
}

int main(void)
{
    gpio_init();
    while(1)
    {
        GPIOB->ODATA ^= GPIO_PIN_2;
        SEGGER_RTT_printf(0, "Hello, Scons!\r\n");
        Delay();
    }
}